<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>标题</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">新增资质项</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="change">修改</a>
    <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    var configureCom = {};
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'matchDict'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var matchDict = layui.matchDict;
        configureCom = layui.configureCom;
        var listData = sessionFun.get(configure.SESSION_ZIZHI_LIST_DATA);
        var cols = [[
            {
                field: 'gradeType', title: '资质序列', templet: function (d) {
                    return '<p>' + matchDict.name(d.gradeType, configure.APTITUDE_SEQUENCE) + '</p>';
                }
            },
            {
                field: 'gradeType', title: '资质项名称', templet: function (d) {
                    var aptitudeIndustry = matchDict.name(d.aptitudeIndustry, configure.APTITUDE_INDUSTRY);//资质行(专)业
                    var aptitudeSpeciality = (d.aptitudeSpeciality ? ('(' + matchDict.name(d.aptitudeSpeciality, configure.APTITUDE_SPECIALITY) + ')') : '');//资质专业
                    var gradeType = matchDict.name(d.gradeType, configure.APTITUDE_SEQUENCE);//资质序列
                    return '<p>' + aptitudeIndustry + aptitudeSpeciality + gradeType + '</p>';
                }
            },
            {field: 'positionDate', title: '就位日期'},
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
        ]];
        configureCom.tableRender(configure.COM_ZIZHI_ITEM_LIST_HTTP, {aptitudeId: listData.id}, cols, 'dataList', 10, '', 'toolbarOrg');
        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            sessionFun.remove(configure.SESSION_ZIZHIITEM_LIST_DATA);
            switch (obj.event) {
                case 'add':
                    editItem('新增资质项', configure.COM_ZIZHI_ITEM_ADD_HTTP);
                    break;
            }
        });
        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_ZIZHIITEM_LIST_DATA, data);
            if (obj.event === 'change') {
                editItem('修改资质项', configure.COM_ZIZHI_ITEM_UPDATE_HTTP);
            } else if (obj.event === 'delete') {
                top.layer.confirm('是否删除当前资质项?', function (index, layero) {
                    configureCom.postDataAjax(configure.COM_ZIZHI_ITEM_DELETE_HTTP, {orgAptitudeTxtIds: data.id}).then(function (res) {
                        top.layer.msg('删除成功！');
                        top.layer.close(index);
                        configureCom.tableReload(true);
                    });
                })
            }
        });


        //新增或修改字典详情
        function editItem(title, url) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.COM_ZIZHI_ITEM_DETAIL_HTML),
                btn: ['保存', '取消'],
                btnAlign: 'c',
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        var ajaxData = res.result;
                        ajaxData.aptitudeId = listData.id;
                        configureCom.postDataAjax(url, ajaxData).then(function (res) {
                            top.layer.close(index);
                            top.layer.msg('保存成功！');
                            configureCom.tableReload(true);
                        });
                    });

                }
            });
        }
    });
</script>
</body>
</html>